package niumao.minecraft.uhc.commands;

import niumao.minecraft.uhc.DefaultSetting;
import niumao.minecraft.uhc.Main;
import niumao.minecraft.uhc.recipes.UHCItem;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class SelectLanguage implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            if (!player.isOp()) {
                player.sendMessage("Only Op can execute this command!");
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("selectlanguage")) {
                if (args.length == 1) {
                    String lang = args[0];
                    if (lang.equalsIgnoreCase("english")) lang = "en_us";
                    else lang = "zh_cn";
                    Main.setLang(lang);
                    new UHCItem().setAllItems();
                    new UHCItem().setRecipe();
                    DefaultSetting.setNPCName(Main.getInstance().getConfig().getString("ServerInfo." + Main.getLang() + ".StartGame"));
                    DefaultSetting.setArmorStandName(Main.getInstance().getConfig().getString("ServerInfo." + Main.getLang() + ".LanguageOptions"));
                    return true;
                }
                return false;
            }
        }
        sender.sendMessage(ChatColor.RED + "only Player can executor this command!");
        return true;
    }
}
